<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>供应商管理</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<style type="text/css">
#searchbar{
   margin-bottom: 10px;
   margin-left:15px;
  }
  .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
.l-button-search {
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
</style>
</head>

<body style="padding:6px; overflow:hidden;">
<div class="navbar">
		<span>您当前的位置：</span>
		基础数据管理 &gt; 供应商管理
</div>

<form action="../../base/supplierInfo/pageFinderSupplier.do" method="post" >
<div id="searchbar">
 供应商名称：<input id="supName" name="supName" type="text" value="${supplier.supName}" />&nbsp;&nbsp;
供应商编号：<input id=account  name="account" type="text"  value="${supplier.account}" />
注册时间：<input type="text" id="createStartDate" name="createStartDate" value="${supplier.createStartDate}" class="Wdate" value="" size="21" readonly="readonly"
			onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,maxDate:'#F{$dp.$D(\'createEndDate\')||\'2020-10-01\'}'})"> - 
		 <input type="text" id="createEndDate" name="createEndDate" value="${supplier.createEndDate}" class="Wdate" value="" size="21" readonly="readonly"
			onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,minDate:'#F{$dp.$D(\'createStartDate\')||\'2013-01-01\'}'})" >
           <input id="btnOK" type="submit" value="查询" class="l-button-search" />
           <input type="button" id="resetBtn" value="重置" class="l-button-search" />
        
</div>
</form>

<div id="maingrid4" style="margin:0; padding:0"></div>
  <div style="display:none;">
  <!-- g data total ttt -->
</div>

<script>

	function getFullTime(date,isStart){
		if(date != null && date != ""){
			if(isStart){
				return date + ' 00:00:00'
			}
			return  date +' 23:59:59';
		}
		return date;
	}
    var basePath='${BasePath}';
    var grid = null;
    $(function () {
    	 // 重置
        $("#resetBtn").click(function(){
    		$('#searchbar :input').not(':submit, :button, :reset').val('').removeAttr('checked').removeAttr('selected');
    	});
    	
        grid = $("#maingrid4").ligerGrid({
            columns: [
            { display: '供应商名称',isSort: false, name: 'supName',width:"12%",align:"left",render:function(item,rowindex){
				return  item.supName;
			}},
            { display: '供应商编号',isSort: false, name: 'account',width:"8%" ,render:function(item,rowindex){
				return  item.account;
			}},
            { display: '联系人',isSort: false, name: 'linkman',width:"9%" ,render:function(item,rowindex){
				return  item.linkman;
			 }},
            { display: '手机号码',isSort: false, name: 'mobileNhonenum',width:"10%" ,render:function(item,rowindex){
				return   item.mobileNhonenum;
			}},
            { display: '电子邮箱',isSort: false, name: 'email',width:"10%",render:function(item,rowindex){
				return   item.email;
			}},
            /* { display: '锁定状态',isSort: false, name: 'state',width:"6%",render:function(rowdata, rowindex, value){
            	var h="正常";
            	
            	if(value=="1")
            	{
            		h="失效";
            	}
            	
            	return  h;
            }}, */
            { display: '注册时间',isSort: false, name: 'registerDate',render:function(item,rowindex){
				return  item.registerDate 
			}} ,
			{ display: '合同开始时间',isSort: false, name: 'contractDayStrat',render:function(item,rowindex){
				return  item.contractDayStrat 
			}} ,
			{ display: '合同结束时间',isSort: false, name: 'contractDayEnd',render:function(item,rowindex){
				return  item.contractDayEnd 
			}} ,
            { display: '操作', isSort: false,render: function (rowdata, rowindex, value){
                var h = "<a href='javascript:detailSupplierCheck(" + rowindex + ")'>查看</a> ";
                h += "<a href='javascript:delSupplierInfoCheck(" + rowindex + ")'>删除</a> ";

                
                //h += "<a href='javascript:setSellByDai(" + rowindex + ")'>代销结算设置</a> ";
                //h += "<a href='javascript:setSellByGou(" + rowindex + ")'>购销结算设置</a> ";
                var roles = ${roleVos};
                for (var i = 0; i < roles.length; i++)
               	{
                	//商品专员,商品主管,管理员
               		if(roles[i].roleCode == 'GOOD_PERSON' || roles[i].roleCode == 'SYSTEM_ADMIN' || roles[i].roleCode == 'GOODS_SUPERVISOR'){
               			h += "<a href='javascript:updateSupplierCheck(" + rowindex + ")'>修改</a> ";
               			/* if(rowdata.state=="0")
                        {//已解锁
                        	h+="<a href='javascript:isUpdateState(\"" + rowdata.code + "\",\"1\")'>失效</a> ";
                        	
                        }else{//已锁定
                        	h+="<a href='javascript:isUpdateState(\"" + rowdata.code + "\",\"0\")'>启动</a> ";
                        }
        				h += "<a href='javascript:updatePassWord(" + rowindex+ ")'>密码重置</a> "; */
               		}
        		}
                return h;
            }
        	}
            ], 
            pageSize:30,
            width: '100%',
            height: '100%',
            dataType: 'server', 
            dataAction: 'server',
            pagesizeParmName: 'pageSize',
            parms: [
					{name: "supName", value:$("#supName").val()},
					{name: "account", value:$("#account").val()},
					{name: "createStartDate", value:getFullTime($("#createStartDate").val(),true)},
					{name: "createEndDate", value:getFullTime($("#createEndDate").val(),false)}
                    ],
			url: "ajaxPageFinderSupplier.do",
            toolbar: { items:items }
        });
    });
    

    var items = "";
    
    var roles = ${roleVos};
    for ( var i = 0; i < roles.length; i++)
    {
    	//商品专员,商品主管,管理员
   		if(roles[i].roleCode == 'GOOD_PERSON' || roles[i].roleCode == 'SYSTEM_ADMIN' || roles[i].roleCode == 'GOODS_SUPERVISOR'){
    		items =[{ text: "新增供应商", click: addSupplierCheck, icon: "add"},{ line: true }];
        }
    	
    	if(roles[i].roleCode == 'FINANCIAL_PRINCIPAL')
    	{
        	items = ([{text: '导出EXCEL', click: doExportExcel, icon: "print"},{ line: true }]);
        }
	}
    
    
    function doExportExcel(){
    	var supName = encodeURI(encodeURI($("#supName").val()));
    	var account = $("#account").val();
    	var createStartDate = $("#createStartDate").val();
    	var createEndDate = $("#createEndDate").val();
    	
    	if(supName == "" && account == "" && createStartDate == "" && createEndDate == ""){
    		$.ligerDialog.warn("导出供应商信息，查询条件不能为空");
    		return false;
    	}
    	
    	var params = "?supName="+supName+"&account="+account+"&createStartDate="+createStartDate+"&createEndDate="+createEndDate;
    	window.location.href = "doExportExcel.do"+params;
    }
    
    function updatePassWord(rowindex){
  	  var code=grid.getData()[rowindex].code;
  	  var m=$.ligerDialog.open({title:'密码重置',url:basePath+'/base/supplierInfo/toUpdatePass.do?code='+code+'&&accountsType='+2,height:350,width:600,isResize: false, isDrag: false });
  	  m.show(); 
    }
    
    function setSellByDai(rowindex){
  	  var code=grid.getData()[rowindex].code;
  	  var m=$.ligerDialog.open({title:'代销结算设置',url:basePath+'/base/supplierInfo/toSellByDai.do?code='+code+'&&accountsType='+2,height:350,width:600,isResize: false, isDrag: false });
  	  m.show(); 
    }
    function setSellByGou(rowindex){
    	  var code=grid.getData()[rowindex].code;
    	  var m=$.ligerDialog.open({title:'购销结算设置',url:basePath+'/base/supplierInfo/toSellByGou.do?code='+code+'&&accountsType='+1,height:350,width:600,isResize: false, isDrag: false });
    	  m.show(); 
      }
      
    
   function addSupplierCheck(){
    	/* var m = $.ligerDialog.open({title: '新增等级', url:basePath+'/member/memberLevelController/toAddMemberLevel.do',height:500,width:700,isResize: false, isDrag: false });
    	m.show(); */
    	var url=basePath+'/base/supplierInfo/toAddSupplier.do';
    	url+="?pTabid="+WIN_TAB.getSelectedTabItemID();
    	window.parent.f_addTab('新增供应商','新增供应商',url);
    }
   
  function updateSupplierCheck(rowindex){
	  var code=grid.getData()[rowindex].code;
	  /* var m=$.ligerDialog.open({title:'修改等级',url:basePath+'/member/memberLevelController/toUpdateMemberLevel.do?levelId='+cid,height:500,width:700,isResize: false, isDrag: false });
	  m.show(); */
      var url=basePath+'/base/supplierInfo/toUpdateSupplier.do?code='+code;
      url+="&pTabid="+WIN_TAB.getSelectedTabItemID();
	  window.parent.f_addTab('修改供应商','修改供应商',url);
  }
   
  function detailSupplierCheck(rowindex){
	  var code=grid.getData()[rowindex].code;
      var url=basePath+'/base/supplierInfo/toDetailSupplier.do?code='+code;
      url+="&pTabid="+WIN_TAB.getSelectedTabItemID();
	  window.parent.f_addTab('详情','详情',url);
  }
  

  //锁定、解锁
 function isUpdateState(code,state){
    	if(code!=null && code!=''){
    		var title="确定锁定?";
    		if(state=="0"){
    			title="确定解锁?";
    		}
    		$.ligerDialog.confirm(title, function (yes) { if(yes){
    	    	$.post("updateLockByState.do?code=" + code+"&state="+state,function(data){
    			  if (data == 'success') {
	          			window.parent.f_tip('操作成功');
	    				reload_cur_tab();
	          	  } else {
	          		window.parent.f_tip('操作失败');
    				reload_cur_tab();
	          	  }	
    	    	});
    	   	}; });
    	};
    };
  
  
  function delSupplierInfoCheck(rowindex){
	   	$.ligerDialog.confirm('确定删除?', function (yes) { if(yes){
	    	var code = grid.getData()[rowindex].code;
	    	$.ajax({
		   		 type:'POST',
		   		 url:basePath+"/base/supplierInfo/checkCommodityCount.do",
		   	     data:{"code":code},
		   		 success : function(data){
		   			 if(data=="fail"){
		   				var s=window.parent.$.ligerDialog.warn("该供应商与商品有关联，不能删除","提示",function(item, Dialog, index) {
			          		window.location.href = basePath+'/base/supplierInfo/pageFinderSupplier.do';
			          		});
			          		$(s.dialog.winbtns).remove();
			          		
		   			 }else if(data == "success"){
		   				/* $.post("checkReturnedCount.do?code="+code,function(data){
		   					 if(data == 'fail'){
		   						var s=window.parent.$.ligerDialog.warn("该供应商与采购单有关联，不能删除","提示",function(item, Dialog, index) {
					          		window.location.href = basePath+'/base/supplierInfo/pageFinderSupplier.do';
					          		});
					          		$(s.dialog.winbtns).remove(); 
		   					 }else if(data == 'success'){
		 		   				$.post("checkAgentCount.do?code="+code,function(data){
		 		   					if(data == 'fail'){
		 		   					  var s=window.parent.$.ligerDialog.warn("该供应商与代销结算有关联，不能删除","提示",function(item, Dialog, index) {
						          		window.location.href = basePath+'/base/supplierInfo/pageFinderSupplier.do';
						          		});
						          		$(s.dialog.winbtns).remove(); 
		 		   					}else if(data =='success'){
		 		   						$.post("checkPurchaseSaleCount.do?code="+code,function(data){
		 		   							if(data == 'fail'){
		 		   							  var s=window.parent.$.ligerDialog.warn("该供应商与购销结算有关联，不能删除","提示",function(item, Dialog, index) {
		 							          		window.location.href = basePath+'/base/supplierInfo/pageFinderSupplier.do';
		 							          		});
		 							          		$(s.dialog.winbtns).remove(); 
		 		   							 }else{ */
		 		   							    $.post("d_supplierInfo.do?code=" + code,function(data){
		 		   								  if (data == 'success') {
		 		   					    			window.parent.f_tip('删除成功');
		 		   									reload_cur_tab();
		 		   					    	     } else {
		 		   					    		  window.parent.f_tip('删除失败');
		 		   								  reload_cur_tab();
		 		   					          }	
		 		   						 });
		 		   							/*  }
		 		   							
		 		   						})
		 		   					}
		 		   				})
				   		 }
		   		    });*/
		   		}
		   	 } 
	   	 });
	   	 }
	  });
    }

</script>
</body>
</html>